/*
 * Copyright (c) Huawei Device Co., Ltd. 2023. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "ef_parser.h"
#include "der_parser.h"
#include "se_timer.h"

#include <gtest/gtest.h>
#include <memory>

#include "channel.h"
#include "ipc_object_stub.h"
#include "loghelper.h"
#include "reader.h"
#include "se_service.h"
#include "service_manager.h"
#include "access_control_enforcer.h"
#include "secure_element_agent.h"
#include "access_rule_cache.h"
#include "arf_manager.h"

namespace OHOS {
namespace SE {
namespace TEST {
using namespace testing::ext;
using namespace OHOS::SE;

class EfParserTest : public testing::Test {
public:
    static void SetUpTestCase() {};
    static void TearDownTestCase() {};
    void SetUp();
    void TearDown();
};

void EfParserTest::SetUp()
{
}

void EfParserTest::TearDown()
{
}

/**
 * @tc.name: ReadFileByPath_Test001
 * @tc.desc: Test ReadFileByPath.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileByPath_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> seAgent;
    std::vector<uint8_t> path;
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    uint16_t rspApdu = 0;
    EXPECT_TRUE(!efParser->ReadFileByPath(path, rspApdu));
}

/**
 * @tc.name: ReadFileByPath_Test003
 * @tc.desc: Test ReadFileByPath.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileByPath_Test003, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> seAgent = std::make_shared<SecureElementAgent>("");
    ArfManager::GetInstance().Initialize(seAgent);
    ArfManager::GetInstance().SetUsedSeName(SE_NAME_SIM);
    std::vector<uint8_t> path = {0x01, 0x02, 0x03, 0x04};
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    uint16_t rspApdu = 0;
    efParser->ReadFileByPath(path, rspApdu);
    EXPECT_TRUE(efParser != nullptr);
}

/**
 * @tc.name: ReadFileByDataSize_Test001
 * @tc.desc: Test ReadFileByDataSize.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileByDataSize_Test001, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> seAgent = std::make_shared<SecureElementAgent>("");
    ArfManager::GetInstance().Initialize(seAgent);
    int offset = 0;
    int dataSize = 0;
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    std::vector<uint8_t> ret = efParser->ReadFileByDataSize(offset, dataSize);
    EXPECT_TRUE(ret.size() == 0);
}

/**
 * @tc.name: ReadFileRecord_Test001
 * @tc.desc: Test ReadFileRecord.
 * @tc.type: FUNC
 */
HWTEST_F(EfParserTest, ReadFileRecord_Test001, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> seAgent = std::make_shared<SecureElementAgent>("");
    ArfManager::GetInstance().Initialize(seAgent);
    uint8_t record = 0;
    std::shared_ptr<EfParser> efParser = std::make_shared<EfParser>();
    std::vector<uint8_t> ret = efParser->ReadFileRecord(record);
    EXPECT_TRUE(ret.size() == 0);
}

} // TEST
} // SE
} // OHOS